/* @Description here

Copyright (C) 2012  Serhii Ratsyborynskyi

This library is free software; you can redistribute it and/or
modify it under the terms of the GNU Lesser General Public
License as published by the Free Software Foundation; either
version 2.1 of the License, or (at your option) any later version.

This library is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
Lesser General Public License for more details.

You should have received a copy of the GNU Lesser General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA

*/

#include <QtGUi>
#include <QStringList>
#include "SimpleUI.hpp"


SimpleUI::SimpleUI( QWidget * ptr /*=0*/) : QWidget ( ptr),
                                            mAudioPlayer(0),
                                            mpOpenFileDialog(0),
                                            mpMultitrackController(0),
                                            mpTrackLayout(0)
{

    /* Init media subsystem */

    initMedia();


    /* Init grafic subsytem */

    initGrafic();



}

void SimpleUI::slotFile()
{
    mpOpenFileDialog->show();
}

void SimpleUI::slotPlay()
{

}


void SimpleUI::slotStop()
{

}

void SimpleUI::slotSetChannelController(QStringList channelList)
{
    if( 0 != mpMultitrackController )
    {
        mpTrackLayout->removeWidget(mpMultitrackController);
        delete mpMultitrackController;
    }

    mpMultitrackController = new CPMpaMultitrackController(channelList, this);
    mpTrackLayout->addWidget(mpMultitrackController);

    connect( mpMultitrackController, SIGNAL(signalMute(QList<bool>)), mAudioPlayer, SLOT(slotMute(QList<bool>)));
    connect( mpMultitrackController, SIGNAL(signalSetChannelVolume(QList<int>)), mAudioPlayer, SLOT(slotSetChannelVolume(QList<int>)));

    this->update();;
}

void SimpleUI::initMedia()
{
    using namespace AudioCore;
    mAudioPlayer=new MPAQtBasePlayer( this );
}

void SimpleUI::initGrafic()
{
    QVBoxLayout * pvbxLayout = new QVBoxLayout;
    CPMpaPlayerController * pPlayerController = new CPMpaPlayerController(this);
    pvbxLayout->addWidget(pPlayerController);
    setLayout(pvbxLayout);
    mpTrackLayout = pvbxLayout;

    connect( mAudioPlayer, SIGNAL(signalReady(bool)), pPlayerController, SLOT(slotEnable(bool)));
    connect( pPlayerController, SIGNAL(signalPlay()), mAudioPlayer, SLOT(slotPlay()));
    connect( pPlayerController, SIGNAL(signalStop()), mAudioPlayer, SLOT(slotStop()));
    connect( pPlayerController, SIGNAL(signalMainVolume(int)), mAudioPlayer, SLOT(slotVolume(int)));
    connect(pPlayerController, SIGNAL(signalFileOpen(QString)), mAudioPlayer, SLOT(slotSetMedia(QString)));
    connect( mAudioPlayer, SIGNAL(signalMediaLoaded(QStringList)),
             this, SLOT(slotSetChannelController(QStringList)));

}

const QString SimpleUI::MEDIA_FILE_PATH  = "D:\\SourceCode\\mpaplayer\\trunk\\Misc\\Sample\\TRK1-00.mp3";
